package cn.wen.util;

import java.io.IOException;
import java.io.PrintWriter;

import org.apache.catalina.core.ApplicationContext;
import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionContext;

/**
* @ClassName: JsonUtil
* @Description: Json工具类
* @author Gavin Nie 
* @E-mail GavinNieZW@163.com
* @date 2014年5月11日 下午6:14:22
*
*/
public class JSONUtil
{
	/**
	* @Title: beanToJson
	* @Description: 类转化成json  并且写到前台
	* @param @param obj
	* @return String    返回类型
	* @throws
	*/
	public static void writeJSON(Object obj){
		  ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
          try {
              PrintWriter out = ServletActionContext.getResponse().getWriter();
              out.write(JSON.toJSONString(obj));	//写到前台
              out.flush();
              out.close();
            } catch (IOException e) {
             e.printStackTrace();
           }
	}
	
	public static void writeText(String text){
		ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
		  try {
              PrintWriter out = ServletActionContext.getResponse().getWriter();
              out.write(text);	//写到前台
              out.flush();
              out.close();
            } catch (IOException e) {
             e.printStackTrace();
           }
	}
	
	
}
